/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Entity;

import java.io.Serializable;
import java.util.Date;
import javax.persistence.Entity;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.ManyToOne;
import javax.persistence.Temporal;

/**
 *
 * @author James
 */
@Entity
public class Review implements Serializable {
    private static final long serialVersionUID = 1L;
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    private Long id;
    private String content;
    private int    ratedPoint;
    @Temporal(javax.persistence.TemporalType.DATE)
    private Date   ratedDate;
    @ManyToOne
    private Partner thePartner;
    @ManyToOne
    private Customer theUser; // Need to make sure a user cannot rate a partner again and again. Future rating will override past rating.
    
    public Review() {
        ratedDate = new Date();
    }
    
    public void createReview(String content, int ratedPoint, Partner thePartner, Customer theUser) {
        this.content    = content;
        this.ratedPoint = ratedPoint;
        this.thePartner = thePartner;
        this.theUser    = theUser;
    }
    
    //Getters and Setters
    public Long getId() {
        return id;
    }

    public void setId(Long id) {
        this.id = id;
    }

    public String getContent() {
        return content;
    }

    public void setContent(String content) {
        this.content = content;
    }

    public int getRatedPoint() {
        return ratedPoint;
    }

    public void setRatedPoint(int ratedPoint) {
        this.ratedPoint = ratedPoint;
    }

    public Partner getPartner() {
        return thePartner;
    }

    public void setPartner(Partner thePartner) {
        this.thePartner = thePartner;
    }

    public Customer getUser() {
        return theUser;
    }

    public void setUser(Customer theUser) {
        this.theUser = theUser;
    }

    public Date getRatedDate() {
        return ratedDate;
    }

    public void setRatedDate(Date ratedDate) {
        this.ratedDate = ratedDate;
    }

    @Override
    public int hashCode() {
        int hash = 0;
        hash += (id != null ? id.hashCode() : 0);
        return hash;
    }

    @Override
    public boolean equals(Object object) {
        // TODO: Warning - this method won't work in the case the id fields are not set
        if (!(object instanceof Review)) {
            return false;
        }
        Review other = (Review) object;
        if ((this.id == null && other.id != null) || (this.id != null && !this.id.equals(other.id))) {
            return false;
        }
        return true;
    }

    @Override
    public String toString() {
        return "Entity.Rating[ id=" + id + " ]";
    }
    
}
